##########################################
##########Getting the data set up##############
##########################################

emotion <- read.csv(file="emotion.csv") ###This file contains the responses for all 280 subjects for their emotional evaluations to the stimuli.

#The question asked: "How do you feel about politics? Place a 0 in the corresponding cell in the table below if the political situation does not elicit the stated emotion. If the situation does elicit that emotion, place a number in the cell that corresponds to the strength of your emotional reaction, from 1 (weak) to 5 (strong). A political situation may evoke more than one emotion."

##The stimuli as are follows, with _1 for the measure of anxiety
##49_1: Living in a community where most of your neighbors affiliate with a political party you don't support
##49_2: Seeing bumper stickers or yard signs in your neighborhood for candidates or parties you don't support
##49_3: Talking with your neighbors or friends about politics when you agree on most things
##49_4: Talking with your neighbors or friends about politics when you disagree on most things
##49_5: Being the only person in your group of friends who supports a candidate, a party, or a political issue
##49_6: Reading a poll predicting the opposition‚Äôs candidate is likely to win an important race
##49_7: Seeing political protests in some other city depicted on TV
##49_8: Seeing live political protests in your area
##49_9: Watching a political debate on television
##49_10: Receiving a political email forward with which you disagree
##49_11: Receiving a political email forward with which you agree
##49_12: Reading a friend‚Äôs post in your Facebook news feed that expresses political views with which you disagree
##49_13: Reading a friend‚Äôs post in your Facebook news feed that expresses political views with which you agree

anxvec <- seq(2,40, by=3)


##########################################
##########Calculating the Proportion Agreement##############
##########################################

##Note that there is an error in the caption for Figure 7 in the Appendix. The proportion shown in the figure is actually those who indicated any anxiety at all (marked a value greater than 0) instead of those who marked greater than 3 on a 5-point scale. 


proptable <- as.data.frame(matrix(NA, 13, 3))

for (i in 1:length(anxvec)){

    prop <- length(which(emotion[,anxvec[i]]>0))/length(which(!is.na(emotion[,anxvec[i]])))
    n <- length(which(!is.na(emotion[,anxvec[i]])))
    ci <- sqrt(((prop)*(1-prop))/n)
proptable[i,1] <- prop
proptable[i,2] <- prop - 1.96*ci
proptable[i,3] <- prop + 1.96*ci

}

names(proptable) <- c("Proportion", "CI Lower", "CI Upper")
anxproptable <- proptable
rownames(anxproptable) <- c("Partisan Minority in Community" ,  "Opposition Signs/Stickers in Neighborhood", "Agreeable Convo with Friends/Neighbors", "Disagreeable Convo with Friends/Neighbors", "Political Minority Among Friends", "Poll Showing Opposition Leading", "Protest on TV", "Protest in Area", "Watching Televised Political Debate", "Receiving Disagreeable Email", "Receiving Agreeable Email", "Reading Disagreeable Facebook Post", "Reading Agreeable Facebook Post")


##########################################
################# Making the Plot ###########
##########################################

seq <- 1:13
seq2 <- order(anxproptable[,1])
color <- "firebrick1"

par(mar=c(3,15,3,1))
plot(anxproptable[seq2,1], seq, col=color, pch=18, xlim=c(0, 1), cex=2, yaxt="n", ylab="", xlab="", font=2, font.lab=2, cex.lab=1.5, main="Proportion of Sample \n Indicating Anxiety for Each Stimulus")
for(i in 1:length(seq)){
lines(c(anxproptable[seq2[i],3], anxproptable[seq2[i], 2]), c(seq[i], seq[i]), col=color)
}
axis(side=2, at=c(13:1), labels=row.names(anxproptable), font=2, cex.axis=.75, las=1)
